function preorder(root) {
    if (!root) return []
    let res = []
    let stack = [root]
    while (stack.length) {
        // 这里就开始弹了 
        const top = stack.pop()
        if (top.right) stack.push(top.right)
        if (top.left) stack.push(top.left) 
        res.push(top.val) 
    }
    return res 
}   
function postorder(root) {
    if (!root) return [] 
    let res = []
    let stack = [root]
    while (stack.length) {
        const top = stack.pop()
        res.push(top.val)
        if (top.left) stack.push(top.left) 
        if (top.right) stack.push(top.right)
    }   
    return res.reverse()
}
function inorder(root) {
    if (!root) return [] 
    let res = []
    return res
}

function levelOrder(root) {
    if (!root) return []
    const res = []
    const queue = [root] 
    while (queue.length) {
        const resArr = []
        let len = queue.length
        for (let i = 0; i < len; i++) {
            let it = queue.shift()
            resArr.push(it.val)
            if (it.left) queue.push(it.left)
            if (it.right) queue.push(it.right)
        }
        res.push(resArr)
    }
    return res
}


export{
    preorder,
    postorder,
    inorder,
    levelOrder
}